package view.GUI.sidepanels;

import java.awt.Component;
import javax.swing.Icon;
import javax.swing.ImageIcon;
import javax.swing.JTree;
import javax.swing.tree.DefaultTreeCellRenderer;
import model.graphic.objects.*;

/**
 *
 * @author Ben
 */
public class InventoryPanelRenderer extends DefaultTreeCellRenderer{
    private Icon gnodeIcon,gBoxnodeIcon,gOutputPortIcon,gInputPortIcon,
                gDispatcherPortIcon, gTriggerPortIcon, gridIcon;

    public InventoryPanelRenderer() {
        gnodeIcon = new ImageIcon("icons\\node.png");
        gBoxnodeIcon = new ImageIcon("icons\\boxnode.png");
        gOutputPortIcon = new ImageIcon("icons\\output.png");
        gInputPortIcon = new ImageIcon("icons\\input.png");
        gDispatcherPortIcon = new ImageIcon("icons\\dispatcher.png");
        gTriggerPortIcon = new ImageIcon("icons\\trigger.png");
        gridIcon = new ImageIcon("icons\\grid.png");
    }


    @Override
    public Component getTreeCellRendererComponent(JTree tree, Object value,
                                                  boolean sel,boolean expanded,
                                                  boolean leaf,int row,boolean hasFocus) {
        super.getTreeCellRendererComponent( tree, value, sel, expanded, leaf, row,hasFocus);
        if (value.getClass().isAssignableFrom(GNode.class)) {
            setIcon(gnodeIcon);
        }else if (value.getClass().isAssignableFrom(GBoxNode.class)) {
            setIcon(gBoxnodeIcon);
        }else if (value.getClass().isAssignableFrom(GOutputPort.class)) {
            setIcon(gOutputPortIcon);
        }else if (value.getClass().isAssignableFrom(GInputPort.class)) {
            setIcon(gInputPortIcon);
        }else if (value.getClass().isAssignableFrom(GDispatcherPort.class)) {
            setIcon(gDispatcherPortIcon);
        }else if (value.getClass().isAssignableFrom(GTriggerPort.class)) {
            setIcon(gTriggerPortIcon);
        }else if(value == tree.getModel().getRoot()){
            setIcon(gridIcon);    
        }
        return this;
    }

}
